<?php

class Emms_Form_Admin_ProductLine extends HTech_Form
{
    protected $_primary  = 'ProductLineId';
    
    public function __construct() 
    {
        parent::__construct();
        
        $this->setName('ProductLine');
        
        $this->setAttrib('title', $this->translate("Product line form"));
        $this->setDescription($this->translate("Edit product line info or add a new one"));
        
        $productLineId = new Zend_Form_Element_Hidden('ProductLineId');
        
        $code = new Zend_Form_Element_Text('Code');
        $code->setLabel("Code")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addFilter('Alpha')
            ->addFilter('StringToUpper')
            ->addValidator('StringLength',false,
                array(
                    'min'      => 3,
                    'max'      => 3,
                    'messages' => $this->translate("Enter a %max% characters value")
                ))
            ->addValidator('Db_NoRecordExists',false,
                array(
                    'table'    => 'product_lines', 
                    'field'    => 'Code', 
                    'exclude'  => array('field' => 'ProductLineId', 'value' => $this->_id),
                    'messages' => $this->translate("Non valid or duplicated entry")                     
                ));
        
        $productLine = new Zend_Form_Element_Text('ProductLine');
        $productLine->setLabel("Product line")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addFilter('Alpha', array('allowwhitespace' => true))
            ->addValidator('StringLength',false,
                array(
                    'min'      => 2,
                    'max'      => 64,
                    'messages' => $this->translate("From %min% to %max% characters only")
                ))
            ->addValidator('Db_NoRecordExists',false,
                array(
                    'table'    => 'product_lines', 
                    'field'    => 'ProductLine', 
                    'exclude'  => array('field' => 'ProductLineId', 'value' => $this->_id),
                    'messages' => $this->translate("Non valid or duplicated entry")                    
                ))
            ->setDescription(null);  
        
        $submit = new Zend_Form_Element_Submit('Submit');
        $submit->setLabel("Submit")
            ->addDecorator(new HTech_Form_Decorator_Button(array('type'=>'submit')));
        
        $this->addElements(array($code,$productLine,$submit,$productLineId));
    }
}